

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int len1, len2;
char s1[2000], s2[2000];
int d[2000][2000];

bool init()
{
    if (scanf("%d", &len1)==EOF) return false;
    scanf("%s", s1);
    
    scanf("%d", &len2);
    scanf("%s", s2);    
	return true;
}    

void deal()
{
    int i, j, k, min;
    memset(d, 0, sizeof(d));
	if (s1[0] == s2[0]) d[0][0] = 0;
	else d[0][0] = 1;

    for (i=1; i<len2; ++i)
        if (s1[0] == s2[i])
                d[0][i] = i;
        else 
                d[0][i] = d[0][i-1]+1;
    
    for (i=1; i<len1; ++i)
        if (s1[i] == s2[0])
                d[i][0] = i;
        else
                d[i][0] = d[i-1][0]+1;
    
    for (i=1; i<len1; ++i)
    {
        for (j=1; j<len2; ++j)
        {
            min = d[i][j-1]+1;

            if (s1[i] == s2[j] && min > d[i-1][j-1])
                min = d[i-1][j-1];
	   if (s1[i] != s2[j] && min > d[i-1][j-1]+1)
	        min = d[i-1][j-1]+1;			
            d[i][j] = min;
        }    
    }    
    /*/debug
    for (i=0; i<len1; ++i, printf("\n"))
        for (j=0; j<len2; ++j)
           printf("%d ", d[i][j]);
    */
    // output 
    printf("%d\n", d[len1-1][len2-1]);
}    


int main()
{
	while (init())    
		deal();
                
    return 0;    
}    
/*
1 a
1 a
1 b
1 a
2 ab
2 ba
3 abc
2 ab
3 abc
2 ac
3 abc
2 bc
*/



